package com.senlingspace.common.enums;

/**
 * 订单业务状态枚举
 * <p>
 * 注意这个枚举中包含了订单表中 business_status、goods_status 2个字段值
 *
 * @author lebronjames
 * @date 2024/07/26
 */
public enum OrderBusinessStatus {

    // =============== 票类订单业务状态枚举 ===============
    UNREDEEMED("UNREDEEMED", "待核销"),
    REDEEMED("REDEEMED", "已核销"),
    PENDING_PAYMENT("PENDING_PAYMENT", "待支付"),
    ORDER_CANCELLED("ORDER_CANCELLED", "订单取消"),
    REFUNDED("REFUNDED", "已退款"),
    WRISTBAND_RECEIVED("WRISTBAND_RECEIVED", "已领手环"),
    DEVICE_RECEIVED("DEVICE_RECEIVED", "已领设备"),
    COMPLETED("COMPLETED", "已完成"),

    // =============== 商品订单业务状态枚举 ===============
    WAITING_FOR_PICKUP("WAITING_FOR_PICKUP", "待取货"),
    WAITING_FOR_SHIPPING("WAITING_FOR_SHIPPING", "待发货"),
    SHIPPED("SHIPPED", "已发货");


    private final String code;
    private final String description;

    OrderBusinessStatus(String code, String description) {
        this.code = code;
        this.description = description;
    }

    public String getCode() {
        return code;
    }

    public String getDescription() {
        return description;
    }

    public static OrderBusinessStatus fromCode(String code) {
        for (OrderBusinessStatus status : OrderBusinessStatus.values()) {
            if (status.getCode().equals(code)) {
                return status;
            }
        }
        throw new IllegalArgumentException("No enum constant with code " + code);
    }

    public static OrderBusinessStatus fromDescription(String description) {
        for (OrderBusinessStatus status : OrderBusinessStatus.values()) {
            if (status.getDescription().equals(description)) {
                return status;
            }
        }
        throw new IllegalArgumentException("No enum constant with description " + description);
    }

    @Override
    public String toString() {
        return description;
    }
}
